package com.gcxy.shop.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@WebServlet(urlPatterns="/logout.do")
public class LogoutServlet extends HttpServlet{
	private static final long serialVersionUID = 1L;
	private Logger logger=LoggerFactory.getLogger(getClass());
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//抽取参数
		try {
			
			//数据转换
			//数据校验
			//业务方法
			HttpSession session=request.getSession();
			session.invalidate();
			//转发与重定向
			request.getRequestDispatcher("/login.jsp").forward(request, response);
			logger.debug("退出系统成功");
		} catch (Exception e) {
			request.setAttribute("error",e.getMessage());
			request.getRequestDispatcher("/login.jsp").forward(request, response);
		
		}
		
		
	}
	

}
